package com.nmsl.medicine.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.medicine.domain.MedicineManufacturer;
import com.nmsl.medicine.service.IMedicineManufacturerService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 药品生产厂家Controller
 * 
 * @author ruoyi
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/medicine/manufacturer")
public class MedicineManufacturerController extends BaseController
{
    @Autowired
    private IMedicineManufacturerService medicineManufacturerService;

    /**
     * 查询药品生产厂家列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:manufacturer:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineManufacturer medicineManufacturer)
    {
        startPage();
        List<MedicineManufacturer> list = medicineManufacturerService.selectMedicineManufacturerList(medicineManufacturer);
        return getDataTable(list);
    }

    /**
     * 导出药品生产厂家列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:manufacturer:export')")
    @Log(title = "药品生产厂家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicineManufacturer medicineManufacturer)
    {
        List<MedicineManufacturer> list = medicineManufacturerService.selectMedicineManufacturerList(medicineManufacturer);
        ExcelUtil<MedicineManufacturer> util = new ExcelUtil<MedicineManufacturer>(MedicineManufacturer.class);
        util.exportExcel(response, list, "药品生产厂家数据");
    }

    /**
     * 获取药品生产厂家详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:manufacturer:query')")
    @GetMapping(value = "/{manufacturerId}")
    public AjaxResult getInfo(@PathVariable("manufacturerId") Long manufacturerId)
    {
        return success(medicineManufacturerService.selectMedicineManufacturerByManufacturerId(manufacturerId));
    }

    /**
     * 新增药品生产厂家
     */
    @PreAuthorize("@ss.hasPermi('medicine:manufacturer:add')")
    @Log(title = "药品生产厂家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicineManufacturer medicineManufacturer)
    {
        return toAjax(medicineManufacturerService.insertMedicineManufacturer(medicineManufacturer));
    }

    /**
     * 修改药品生产厂家
     */
    @PreAuthorize("@ss.hasPermi('medicine:manufacturer:edit')")
    @Log(title = "药品生产厂家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicineManufacturer medicineManufacturer)
    {
        return toAjax(medicineManufacturerService.updateMedicineManufacturer(medicineManufacturer));
    }

    /**
     * 删除药品生产厂家
     */
    @PreAuthorize("@ss.hasPermi('medicine:manufacturer:remove')")
    @Log(title = "药品生产厂家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{manufacturerIds}")
    public AjaxResult remove(@PathVariable Long[] manufacturerIds)
    {
        return toAjax(medicineManufacturerService.deleteMedicineManufacturerByManufacturerIds(manufacturerIds));
    }
}
